#include<bits/stdc++.h>
using namespace std;

//const int N = 2e5 + 10;
const int N = 2e2 + 10;
/*
   int n, a[N];
   int dp[N];
   int last[N];
   int head[N * 10];
   int pre[N];//ji lu uh yi ge xd ts uu
   int la[N]; //jilu uhyige yise vi
   int type[N];
 */
int a[N];
int n;
int type[N];
int ans;

int calc() {
	int ans1 = 0;
	for(int i = 2; i <= n; ++ i) {
		for(int j = i - 1; j >= 1; --j) {
			if(a[i] == a[j] and type[i] == type[j]) {
				ans1 += a[i];
				break;
			}
		}
	}
	return ans1;
}

void dfs(int u) {
	if(u > n) {
		ans = max(ans, calc());
		return;
	}
	for(int i = 1; i <= 2; ++ i) {
		type[u] = i;
		dfs(u + 1);
		type[u] = 0;
	}
}

signed main() {
	freopen("color.in", "r", stdin);
	freopen("color.out", "w", stdout);
	int T;
	cin >> T;
	while(T--) {
		memset(a, 0, sizeof(a));
		memset(type, 0, sizeof(type));
		ans = 0;

		cin >> n;

		for(int i = 1; i <= n; ++ i) {
			cin >> a[i];
		}

		type[1] = 1;
		dfs(2);
		cout << ans << endl;

	}
	/*
	 *	   scanf("%d", &n);
	 *	   for(int i = 1; i <= n; ++ i) {
	 *	   last[i] = last[i - 1];
	 *	   scanf("%d", a + i);
	 *	   if(a[i] == a[i - 1]) {
	 *	   ++ last[i];
	 *	   }
	 *	   pre[i] = head[a[i]];
	 *	   head[a[i]] = i;
	 *	   }
	 *
	 *	//dp
	 *	for(int i = 2; i <= n; ++ i) {
	 *	int j = pre[i];
	 *	int ans = dp[i - 1];
	 *	if(j == i - 1) {
	 *	ans += a[i];
	 *	j = pre[j];
	 *	}
	 *	while(j) {
	 *	int u = dp[j - 1] + a[i] + last[i - 1] - last[j];
	 *	if(a[j - 1] == a[j + 1] or a[j - 1] == a[j]) {
	 *	u += a[j - 1];
	 *	}
	 *ans = max(ans, u);
	 *if(ans < u) {
	 *ans = u;
	 *}
	 *j = pre[j];
	 *}
	 *dp[i] = ans;
	 *}
	 *
	 *cout << dp[n];
	 */
	fclose(stdin);
	fclose(stdout);
	return 0;
}
/*bool flag bcji mzyb vijxjiig de
 *
 */
